<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // \App\Models\User::factory(10)->create();
        DB::table('user')->insert([
            'id' => 1,
            'username' => 'admin',
            'password' => Hash::make('123456'),
            'lastlogin' => time(),
        ]);

        DB::table('role')->insert([
            'id' => 1,
            'name' => '管理员',
            'user_id' => 1,
        ]);

        $routes = [];
        $routes[] = ['id' => 1,'name' => '后台首页','route' => 'App\Http\Controllers\Admin\IndexController@index','user_id' => 1];
        $routes[] = ['id' => 17,'name' => '后台','route' => 'App\Http\Controllers\Admin\IndexController@layout','user_id' => 1];

        $routes[] = ['id' => 2,'name' => '用户列表','route' => 'App\Http\Controllers\Admin\UserController@index','user_id' => 1];
        $routes[] = ['id' => 3,'name' => '用户新增','route' => 'App\Http\Controllers\Admin\UserController@add','user_id' => 1];
        $routes[] = ['id' => 4,'name' => '用户编辑','route' => 'App\Http\Controllers\Admin\UserController@edit','user_id' => 1];
        $routes[] = ['id' => 5,'name' => '用户删除','route' => 'App\Http\Controllers\Admin\UserController@del','user_id' => 1];
        $routes[] = ['id' => 6,'name' => '用户角色','route' => 'App\Http\Controllers\Admin\UserController@role','user_id' => 1];
        $routes[] = ['id' => 33,'name' => '用户头像','route' => 'App\Http\Controllers\Admin\UserController@avatar','user_id' => 1];

        $routes[] = ['id' => 7,'name' => '角色列表','route' => 'App\Http\Controllers\Admin\RoleController@index','user_id' => 1];
        $routes[] = ['id' => 8,'name' => '角色新增','route' => 'App\Http\Controllers\Admin\RoleController@add','user_id' => 1];
        $routes[] = ['id' => 9,'name' => '角色编辑','route' => 'App\Http\Controllers\Admin\RoleController@edit','user_id' => 1];
        $routes[] = ['id' => 10,'name' => '角色删除','route' => 'App\Http\Controllers\Admin\RoleController@del','user_id' => 1];
        $routes[] = ['id' => 11,'name' => '角色授权','route' => 'App\Http\Controllers\Admin\RoleController@permission','user_id' => 1];

        $routes[] = ['id' => 12,'name' => '权限列表','route' => 'App\Http\Controllers\Admin\PermissionController@index','user_id' => 1];
        $routes[] = ['id' => 13,'name' => '权限增加','route' => 'App\Http\Controllers\Admin\PermissionController@add','user_id' => 1];
        $routes[] = ['id' => 14,'name' => '权限编辑','route' => 'App\Http\Controllers\Admin\PermissionController@edit','user_id' => 1];
        $routes[] = ['id' => 15,'name' => '权限删除','route' => 'App\Http\Controllers\Admin\PermissionController@del','user_id' => 1];

        $routes[] = ['id' => 16,'name' => '缓存首页','route' => 'App\Http\Controllers\Admin\CacheController@index','user_id' => 1];
        $routes[] = ['id' => 18,'name' => '邮件首页','route' => 'App\Http\Controllers\Admin\EmailController@index','user_id' => 1];
        $routes[] = ['id' => 19,'name' => '邮件设置','route' => 'App\Http\Controllers\Admin\EmailController@edit','user_id' => 1];
        $routes[] = ['id' => 20,'name' => '清空缓存','route' => 'App\Http\Controllers\Admin\CacheController@flush','user_id' => 1];
        $routes[] = ['id' => 22,'name' => '队列管理','route' => 'App\Http\Controllers\Admin\QueueController@index','user_id' => 1];
        $routes[] = ['id' => 23,'name' => '队列模式','route' => 'App\Http\Controllers\Admin\QueueController@set','user_id' => 1];
        $routes[] = ['id' => 24,'name' => '失败队列','route' => 'App\Http\Controllers\Admin\QueueController@failed','user_id' => 1];
        $routes[] = ['id' => 25,'name' => '启动队列','route' => 'App\Http\Controllers\Admin\QueueController@work','user_id' => 1];

        $routes[] = ['id' => 26,'name' => 'Api列表','route' => 'App\Http\Controllers\Admin\ApiController@index','user_id' => 1];
        $routes[] = ['id' => 27,'name' => 'Api增加','route' => 'App\Http\Controllers\Admin\ApiController@add','user_id' => 1];
        $routes[] = ['id' => 28,'name' => 'Api编辑','route' => 'App\Http\Controllers\Admin\ApiController@edit','user_id' => 1];
        $routes[] = ['id' => 29,'name' => 'Api删除','route' => 'App\Http\Controllers\Admin\ApiController@del','user_id' => 1];

        $routes[] = ['id' => 21,'name' => '网站设置','route' => 'App\Http\Controllers\Admin\SettingController@index','user_id' => 1];
        $routes[] = ['id' => 30,'name' => '短信设置','route' => 'App\Http\Controllers\Admin\SettingController@sms','user_id' => 1];
        $routes[] = ['id' => 31,'name' => '微信设置','route' => 'App\Http\Controllers\Admin\SettingController@wechat','user_id' => 1];
        $routes[] = ['id' => 32,'name' => 'OSS设置','route' => 'App\Http\Controllers\Admin\SettingController@oss','user_id' => 1];
        $routes[] = ['id' => 34,'name' => '支付宝设置','route' => 'App\Http\Controllers\Admin\SettingController@payali','user_id' => 1];
        $routes[] = ['id' => 35,'name' => '微信支付设置','route' => 'App\Http\Controllers\Admin\SettingController@paywechat','user_id' => 1];

        DB::table('permission')->insert($routes);

        DB::table('user_role')->insert([
            'user_id' => 1,
            'role_id' => 1,
        ]);

        $role_permission = [];
        for($i=1;$i<=count($routes);$i++){
            $role_permission[] =['role_id' => 1,'permission_id' => $i];
        }
        DB::table('role_permission')->insert($role_permission);
    }
}
